package com.pug.security.controller.user;

import com.pug.security.pojo.SysLoginUser;
import com.pug.security.service.security.ILoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private ILoginUserService loginUserService;

    @GetMapping("/user/get/{id}")
    @PreAuthorize("hasAuthority('user:list')")
    public SysLoginUser getUser(@PathVariable("id") Long id) {
        return loginUserService.getById(id);
    }

    @GetMapping("/user/list")
    @PreAuthorize("hasAuthority('course:list')")
    public List<SysLoginUser> userList() {
        return loginUserService.list();
    }

    @GetMapping("/user/search")
    @PreAuthorize("hasAnyAuthority('course:list','user:list')")
    public List<SysLoginUser> userSearch() {
        return loginUserService.list();
    }


}
